/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.chrfra.controller;
import edu.chl.chrfra.backing.AddProductBackingBean;
import edu.chl.chrfra.backing.PersistenceUtilityBean;
import edu.chl.chrfra.controller.IJpaCtrl;
import edu.chl.chrfra.entities.Car;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;


@ManagedBean
@RequestScoped
public class AddProductControllerBean {

    @ManagedProperty(value="#{addProductBackingBean}")
    private AddProductBackingBean apbb;

    @ManagedProperty(value="#{persistenceUtilityBean}")
    private PersistenceUtilityBean persHelpBean;

    public PersistenceUtilityBean getPersHelpBean() {
        return persHelpBean;
    }

    public void setPersHelpBean(PersistenceUtilityBean persHelpBean) {
        this.persHelpBean = persHelpBean;
    }
    
    public AddProductBackingBean getApbb() {
        return apbb;
    }

    public void setApbb(AddProductBackingBean addProdBean) {
        this.apbb = addProdBean;
    }

    /** Creates a new instance of AddProductControllerBean */
    public AddProductControllerBean() {
    }

    public String addProduct() {
        IJpaCtrl<Car> jpaControl = persHelpBean.getJpaCtrl();
        Car c = new Car();
        c.setMake(apbb.getProdName());
        c.setModell(apbb.getCatName());
        c.setPrice(apbb.getPrice());
        c.setMileage(apbb.getMileage());
        c.setYear(apbb.getYear());
        //c.setImage(apbb.getImage());
        //Logger.getAnonymousLogger().log(Level.INFO, String.format("BILD**********************************", apbb.getImage().length));
        jpaControl.create(c);
        /*
        jpaControl.create(new Car(apbb.getProdName(),
                apbb.getCatName(), apbb.getPrice()));
         */
         
        return "onAddProduct";
    }
}
